package com.xiaotu.service.talent.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xiaotu.dao.common.CommonMapper;
import com.xiaotu.model.TVSubModel;
import com.xiaotu.service.talent.SwTalentPoolService;
import com.xiaotu.vo.SwListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangxiao
 * @create 2021-08-24 16:45
 */
@Service
public class SwTalentPoolServiceImpl implements SwTalentPoolService {

    public static final List<Map<String, Object>> TVTYPES = new ArrayList<>();

    static {
        HashMap<String, Object> tvtype13 = new HashMap<>();
        tvtype13.put("tvType", "1,3");
        tvtype13.put("typeName", "剧集");
        HashMap<String, Object> tvtype2 = new HashMap<>();
        tvtype2.put("tvType", "2");
        tvtype2.put("typeName", "电影");
        HashMap<String, Object> tvtype6 = new HashMap<>();
        tvtype6.put("tvType", "6");
        tvtype6.put("typeName", "网络电影");
        TVTYPES.add(tvtype13);
        TVTYPES.add(tvtype2);
        TVTYPES.add(tvtype6);
    }

    @Autowired
    private CommonMapper commonMapper;

    @Override
    public List<Map<String, Object>> getTvTypes() {
        return TVTYPES;
    }

    @Override
    public List<TVSubModel> getTVSubs(String tvType) {
        return commonMapper.getTVSubList(tvType);
    }

    @Override
    public List<SwListVo> getSwTalentList(String starName, String tvType, String subName, String sex, Integer startAge, Integer endAge) {
        if (StrUtil.isNotEmpty(starName)) {
            return commonMapper.getSwTalentUnionList(starName);
        } else {
            String[] subNameArr = ObjectUtil.isEmpty(subName) ? null : subName.split(",");
            if (ObjectUtil.isNotEmpty(tvType)) {
                String[] oldArr = tvType.split(",");
                Integer[] newArr = new Integer[oldArr.length];
                for (int i = 0; i < oldArr.length; i++) {
                    newArr[i] = Integer.parseInt(oldArr[i]);
                }
                return commonMapper.getSwTalentList(tvType, newArr, subNameArr, sex, startAge, endAge);
            }
            return commonMapper.getSwTalentList(null, null, subNameArr, sex, startAge, endAge);
        }
    }

}
